package com.learning.netease.optimize.trx.dispatchservice.api;

import com.learning.netease.optimize.trx.dispatchservice.service.DispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * ClassName: DispatchController
 * Description:
 * Date: 2019/1/30 14:48 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@RestController
@RequestMapping("dispatch")
public class DispatchController {

    @Autowired
    private DispatchService dispatchService;

    @GetMapping
    public String dispatch(String orderId) throws Exception {

        // 模拟业务耗时，接口调用超时。
        // 导致运单表有数据，但是订单事务回滚后，订单表没有数据
        if (Objects.equals("1000001", orderId)) {
            Thread.sleep(3000L);
        }

        // 将外卖订单分配给送餐小哥
        dispatchService.dispatch(orderId);
        return "ok";
    }
}
